$(document).ready(function() {
	// $.fn = fn || {};	
	//$.fn.editable = {};
	//$.fn.editable.defaults =  {};
	
    //toggle `popup` / `inline` mode
    $.fn.editable.defaults.mode = 'popup';     
    
    //make username editable
    $('#username').editable();	
    $('#username0').editable();
	
	    //editables 
    $('username0').editable({
           url: '/post',
           type: 'text',
           pk: 1,
           name: 'username',
           title: 'Enter username'
    });
	
	$('#firstname').editable({
        validate: function(value) {
           if($.trim(value) == '') return 'This field is required';
        }
    });
	
	$('#sex').editable({
        prepend: "not selected",
        source: [
            {value: 1, text: 'Male'},
            {value: 2, text: 'Female'}
        ],
        display: function(value, sourceData) {
             var colors = {"": "gray", 1: "green", 2: "blue"},
                 elem = $.grep(sourceData, function(o){return o.value == value;});
                 
             if(elem.length) {    
                 $(this).text(elem[0].text).css("color", colors[value]); 
             } else {
                 $(this).empty(); 
             }
        }   
    });    
    
    //make status editable
    $('#status').editable({
        type: 'select',
        title: 'Select status',
        placement: 'right',
        value: 2,
        source: [
            {value: 1, text: 'status 1'},
            {value: 2, text: 'status 2'},
            {value: 3, text: 'status 3'}
        ]
        /*
        //uncomment these lines to send data on server
        ,pk: 1
        ,url: '/post'
        */
    });
	
	$('#dob').editable();
	$('#event').editable({
        placement: 'right',
        combodate: {
            firstItem: 'name'
        }
    });
	$('#group').editable({
		   showbuttons: false 
	}); 		
	
    $('#tbl-status').editable({
        type: 'select',
        title: 'Select status',
        placement: 'right',
        value: 2,
        source: [
            {value: 1, text: 'Active'},
            {value: 2, text: 'Disabled'},
            {value: 3, text: 'Suspended'}
        ]
        ,pk: 1
        ,url: '/post'
        
    });	
});